package com.ruixi.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author lrzg
 * @date 2021-10-19 11:16
 * @Description swagger和knife4j文档配置
 */
@Configuration
@EnableKnife4j //开启Knife4j
public class Knife4jConfig {

    /**
     * 是否开启Knife4j
     */
    @Value("${knife4j.enable}")
    private boolean enabled;
    @Bean
    public Docket userApi(){
        return new Docket(DocumentationType.OAS_30)
//                .enable(enabled)
                .groupName("系统管理")
                .apiInfo(apiInfo())
                .select()
                //这里指定Controller扫描包路径（项目路径也行）
                //方式一：配置扫描，所有想要在Knife4j界面统一管理的接口，必须再此包下
//                .apis(RequestHandlerSelectors.basePackage("com.ruixi.controller"))
                //只要当方法上有@ApiOperation注解时，才能生成对应的接口文档
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }
//    @Bean
//    public Docket monitorDocket(){
//        return new Docket(DocumentationType.OAS_30)
//                .groupName("监控系统")
//                .apiInfo(apiInfo())
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.ruixi.controller"))
//                .paths(PathSelectors.any())
//                .build();
//    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("RuiXi管理系统Swagger文档")
                .description("RuiXi管理系统Swagger文档,版本V1.0.0")
                .version("1.0.0")
                .contact(new Contact("RuiXi","http://www/ruixi.com","ruixi@126.com"))
                //服务Url
                .termsOfServiceUrl("http://blog.ruixi.com")
                .build();

    }
}
